const { resolve } = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const webpack = require('webpack')
// 
const AddAssetHtmlWebpackPlugin = require('add-asset-html-webpack-plugin')

/**
 * dll 动态链接库，对代码进行单独打包
 * 指示webpack哪些库不参与打包
 * 正常情况node_modules的包会被打包成一个文件
 * dll可以将这些库拆出来单独的打包成一些文件
 * 
 */
module.exports = {
  entry: './src/js/index.js',
  output: {
    filename: 'js/built.[contenthash:10].js',
    path: resolve(__dirname, 'build')
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: './src/index.html',
      minify: {
        collapseWhitespace: true,
        removeComments: true
      }
    }),
    // 告诉webpack哪些库不参与打包，同时使用的名称也改变
    new webpack.DllReferencePlugin({
      manifest: resolve(__dirname, 'dll/manifest.json')
    }),
    // 将某个文件打包输出出去，并在html中自动引入该资源
    new AddAssetHtmlWebpackPlugin({
      filepath: resolve(__dirname, 'dll/jquery.js')
    })
  ],
  mode: 'production',
  
}
